﻿using D.Medicalcare.Domain.Entities;
using D.Medicalcare.ErrorCode;
using D.Medicalcare.Infrastructure.Interfaces;
using D.Medicalcare.Read.API.Application.Command.MenuCommand;
using MediatR;

namespace D.Medicalcare.Read.API.Application.Handler.MenuHandler
{
    /// <summary>
    /// 修改反填菜单处理
    /// </summary>
    public class QueryMenuHandler : IRequestHandler<QueryMenuCommand, APIResult<List<Menu>>>
    {
        private readonly IBaseRepository<Menu> menuRep;
        /// <summary>
        /// 构造方法
        /// </summary>
        /// <param name="menuRep"></param>
        public QueryMenuHandler(IBaseRepository<Menu> menuRep)
        {
            this.menuRep = menuRep;
        }
        /// <summary>
        /// 处理
        /// </summary>
        /// <param name="request">命令</param>
        /// <param name="cancellationToken">命令</param>
        /// <returns></returns>
        public async Task<APIResult<List<Menu>>> Handle(QueryMenuCommand request, CancellationToken cancellationToken)
        {
            APIResult<List<Menu>> result = new APIResult<List<Menu>>();
            result.Code = APIEnum.Success;
            result.Msg = "查询成功";
            var a = menuRep.GetAll();
            result.Data = a.ToList();
            return await Task.FromResult(result);
        }
    }
}
